package com.manli.api.controller;

import java.util.Arrays;
import java.util.Map;
import com.manli.api.pojo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.manli.api.base.annotation.Permissions;
import com.manli.api.dto.ViewPermission;
import com.manli.api.service.ViewPermissionService;



/**
 * VIEW
 *
 * @author manli
 * @email 
 * @date 2020-04-29 15:46:27
 */
@Api(value="/viewpermission", tags="VIEW")
@RestController
@RequestMapping("api/viewpermission")
public class ViewPermissionController {
    @Autowired
    private ViewPermissionService viewPermissionService;

    /**
     * 列表
     */
    @ApiOperation(value = "VIEW列表",notes = "")
    @PostMapping("/list")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN_PERMISSONS)
    public Result list(@RequestBody Map<String, Object> params){
        return viewPermissionService.queryPage(params);
    }

    /**
     * 全部数据信息
     */
    @ApiOperation(value = "VIEW全部数据信息",notes = "")
    @PostMapping("/all")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN_PERMISSONS)
    public Result all(@RequestBody Map<String, Object> params){
        return viewPermissionService.queryAll(params);
    }

    /**
     * 全部api接口信息，tree格式
     */
    @PostMapping("/treeApiAll")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN_PERMISSONS)
    public Result treeApiAll(@RequestBody Map<String, Object> params){
        return viewPermissionService.treeApiAll(params);
    }

    /**
     * 全部菜单权限信息，tree格式
     */
    @PostMapping("/treeMenuAll")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN_PERMISSONS)
    public Result treeMenuAll(@RequestBody Map<String, Object> params){
        return viewPermissionService.treeMenuAll(params);
    }

    /**
     * 全部api接口保存
     */
    @PostMapping("/apiPermissionSave")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN_PERMISSONS)
    public Result apiPermissionSave(@RequestBody Map<String, Object> params){
        return viewPermissionService.apiPermissionSave(params);
    }

    /**
     * 全部菜单权限信息，tree格式
     */
    @PostMapping("/menuPermissionSave")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN_PERMISSONS)
    public Result menuPermissionSave(@RequestBody Map<String, Object> params){
        return viewPermissionService.menuPermissionSave(params);
    }

    /**
     * 单条信息
     */
    @ApiOperation(value = "VIEW单条信息",notes = "VIEW单条信息")
    @GetMapping("/info/{permissionId}")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN_PERMISSONS)
    public Result info(@PathVariable("permissionId") Integer permissionId){
        return viewPermissionService.getById(permissionId);
    }

    /**
     * 保存
     */
    @ApiOperation(value = "VIEW保存",notes = "VIEW保存")
    @PostMapping("/save")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN_PERMISSONS)
    public Result save(@RequestBody ViewPermission viewPermission){
        return viewPermissionService.save(viewPermission);
    }

    /**
     * 修改
     */
    @ApiOperation(value = "VIEW修改",notes = "VIEW修改")
    @PostMapping("/update")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN_PERMISSONS)
    public Result update(@RequestBody ViewPermission viewPermission){
        return viewPermissionService.updateById(viewPermission);
    }

    /**
     * 删除单条数据
     */
    @ApiOperation(value = "VIEW删除",notes = "VIEW删除")
    @ApiImplicitParam(name = "permissionIds", value = "id",dataType = "int", required = true)
    @DeleteMapping("/delete")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN_PERMISSONS)
    public Result delete(Integer permissionId){
        return viewPermissionService.removeById(permissionId);
    }

    /**
     * 删除多条数据
     */
    @ApiOperation(value = "VIEW删除",notes = "VIEW删除")
    @ApiImplicitParam(name = "permissionIds", value = "id数组,json字符串",dataType = "id数组,json字符串", required = true)
    @DeleteMapping("/deleteIds")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN_PERMISSONS)
    public Result deleteIds(@RequestBody Integer[] permissionIds){
        return viewPermissionService.removeByIds(Arrays.asList(permissionIds));
    }

}
